<template>
  <div id="app">
    <el-container>
      <el-header>
        <el-menu router v-show="show" class="el-menu-demo" mode="horizontal">
          <el-menu-item index="/home">首页</el-menu-item>
          <el-menu-item index="/shang">商品</el-menu-item>
          <el-menu-item index="/ding">订单</el-menu-item>
          <el-menu-item index="/hui">会员</el-menu-item>
          <el-menu-item index="/she">设置</el-menu-item>
          <el-button type="success" class="btn" @click="exit"
            >退出登录</el-button>
        </el-menu>
      </el-header>
      <el-container>
        <router-view></router-view>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: false,
    };
  },
  // 监听 如果是登录页面就隐藏
  watch: {
    "$route.path": {
      handler(newval, oldval) {
        if (newval == "/login") {
          this.show = false;
        } else {
          this.show = true;
        }
      },
    },
  },
  methods: {
    // 退出登录
    exit() {
      this.$confirm("确定退出登录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出登录成功!",
          });
          localStorage.removeItem("token");
          this.$router.push({ path: "/login" });
          this.$http("http://ceshi5.dishait.cn/admin/logout", "post");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出登录",
          });
        });
    },
  },
};
</script>
<style   scoped>
.el-header,
.el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
}
body > .el-container {
  margin-bottom: 40px;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}
.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>